#ifndef SINGLEINSTANCECHECKER_H
#define SINGLEINSTANCECHECKER_H

#include <QDebug>
#include <QLocalServer>
#include <QLocalSocket>
#include <QObject>
#include <QWidget>

class SingleInstanceChecker : public QObject
{
    Q_OBJECT
public:
    explicit SingleInstanceChecker(const QString &serverName,
                                   QWidget *mainWindow,
                                   QObject *parent = nullptr);

    ~SingleInstanceChecker();
    bool isAnotherInstanceRunning();
    bool isSingleInstance() const;

private:
    QLocalServer *createLocalServer();
    void sendBringToFrontMessage();
private slots:
    void handleNewConnection();

private:
    QString m_serverName;
    QLocalServer *m_localServer;
    QWidget *m_mainWindow;
};

#endif // SINGLEINSTANCECHECKER_H
